/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.passwords;

import org.json.JSONObject;
import org.webos.java.base.Dialog;
import org.webos.java.base.DialogType;
import org.webos.java.base.RemoteMessage;
import org.webos.java.base.SystemManager;
import org.webos.java.base.utils.CryptoUtil;

/**
 *
 * @author kostya
 */

@DialogType(jsClass="passwords.MobileView")
public class MobileView extends Dialog<PasswordManager>{

    PasswordItem item = null;

    MobileView(PasswordManager aManager, PasswordItem aPasswordItem) {
        super(aManager);
        item = aPasswordItem;
        String masterPassword = getApplication().getPassword();
        if(masterPassword!=null){
            item.objectTOJSON(getData());
            getData().putOpt("login", SystemManager.prepareTextForView(
                    CryptoUtil.decode(masterPassword, item.login), true));
            getData().putOpt("password", SystemManager.prepareTextForView(
                    CryptoUtil.decode(masterPassword, item.password), true));
            show();
        }
    }

    @RemoteMessage
    public void editEntry(JSONObject aObject){
        closeDialog(aObject);
        new EntryEditor(getApplication(), item);
    }
}
